package com.ldj.struts.action;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.ldj.common.SystemSession;
import com.ldj.hibernate.ViewOrgan;
import com.ldj.hibernate.ViewOrganDAO;
import com.ldj.hibernate.ViewOrganId;

public class ViewOrganAction extends DispatchAction {
	public ActionForward xls(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewOrganDAO dao = new ViewOrganDAO(request, response);
		List list = dao.find();
		request.setAttribute("list", list);
		request.setAttribute("organ", SystemSession.getUserOrgan(request));
		return mapping.findForward("xls");
	}
	
	public ActionForward detail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewOrganDAO dao = new ViewOrganDAO(request, response);
		List list = dao.find();
		request.setAttribute("list", list);
		return mapping.findForward("detail");
	}
	
	public ActionForward pic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewOrganDAO dao = new ViewOrganDAO(request, response);
		List list = dao.find();
		Hashtable rd = new Hashtable();
		rd.put("barTitle", "劳动保障监察组织柱状图");
		rd.put("domain", "机构级别");
		rd.put("range", "个（人）数");
		List dList = new Vector();
		if(list != null && list.size() > 0){
			for(int i = 0; i < list.size(); i ++){
				ViewOrgan vc = (ViewOrgan)list.get(i);
				ViewOrganId contract = vc.getId();
				Hashtable hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "应建机构");
				hd.put("value", contract.getSupOrganYOrgan());
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "专设机构");
				hd.put("value", contract.getSupOrganZOrgan());
				dList.add(hd);
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "合设机构");
				hd.put("value", contract.getSupOrganHOrgan());
				dList.add(hd);
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "专职监察员");
				hd.put("value", contract.getSupOrganZPerson());
				dList.add(hd);
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "兼职监察员");
				hd.put("value", contract.getSupOrganJPerson());
				dList.add(hd);
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getLevelName());
				hd.put("title", "监察协管员");
				hd.put("value", contract.getSupOrganXPerson());
				dList.add(hd);
			}
		}		
		rd.put("data", dList);
		request.getSession().setAttribute("data", rd);
		return mapping.findForward("pic");
	}
	
}